package com.ruoyi.ma.controller;

import java.text.ParseException;
import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import com.ruoyi.ma.domain.vo.MaMaterialPlanDataDetailsReturnVo;
import com.ruoyi.ma.domain.vo.MaMaterialProgressDataDetailsReturnVo;
import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaCheckLogin;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.validate.QueryGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.ma.domain.vo.MaMaterialProgressDetailsVo;
import com.ruoyi.ma.domain.bo.MaMaterialProgressDetailsBo;
import com.ruoyi.ma.service.IMaMaterialProgressDetailsService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 材料进度详情
 *
 * @author llb
 * @date 2024-11-01
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/ma/materialProgressDetails")
public class MaMaterialProgressDetailsController extends BaseController {

    private final IMaMaterialProgressDetailsService iMaMaterialProgressDetailsService;

    /**
     * 查询材料进度详情列表
     */
    @SaCheckLogin
    @GetMapping("/list")
    public TableDataInfo<MaMaterialProgressDetailsVo> list(MaMaterialProgressDetailsBo bo, PageQuery pageQuery) {
        return iMaMaterialProgressDetailsService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出材料进度详情列表
     */
    @SaCheckLogin
    @Log(title = "材料进度详情", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(MaMaterialProgressDetailsBo bo, HttpServletResponse response) {
        List<MaMaterialProgressDetailsVo> list = iMaMaterialProgressDetailsService.queryList(bo);
        ExcelUtil.exportExcel(list, "材料进度详情", MaMaterialProgressDetailsVo.class, response);
    }

    /**
     * 获取材料进度详情详细信息
     *
     * @param progressDetailsId 主键
     */
    @SaCheckLogin
    @GetMapping("/{progressDetailsId}")
    public R<MaMaterialProgressDetailsVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long progressDetailsId) {
        return R.ok(iMaMaterialProgressDetailsService.queryById(progressDetailsId));
    }

    /**
     * 新增材料进度详情
     */
    @SaCheckLogin
    @Log(title = "材料进度详情", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody MaMaterialProgressDetailsBo bo) {
        return toAjax(iMaMaterialProgressDetailsService.insertByBo(bo));
    }

    /**
     * 修改材料进度详情
     */
    @SaCheckLogin
    @Log(title = "材料进度详情", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody MaMaterialProgressDetailsBo bo) {
        return toAjax(iMaMaterialProgressDetailsService.updateByBo(bo));
    }

    /**
     * 删除材料进度详情
     *
     * @param progressDetailsIds 主键串
     */
    @SaCheckLogin
    @Log(title = "材料进度详情", businessType = BusinessType.DELETE)
    @DeleteMapping("/{progressDetailsIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] progressDetailsIds) {
        return toAjax(iMaMaterialProgressDetailsService.deleteWithValidByIds(Arrays.asList(progressDetailsIds), true));
    }

    /**
     * 获取详情列表不分页
     */
    @SaCheckLogin
    @GetMapping("/allList")
    public R<List<MaMaterialProgressDetailsVo>> allList(MaMaterialProgressDetailsBo bo) throws ParseException {
        return R.ok(iMaMaterialProgressDetailsService.allList(bo));
    }


    /**
     * 保存材料签收详情
     */
    @SaCheckLogin
    @Log(title = "保存材料签收详情", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping("/updateDetails")
    public R<Void> updateDetails(@Validated(AddGroup.class) @RequestBody MaMaterialProgressDataDetailsReturnVo bo) {
        return toAjax(iMaMaterialProgressDetailsService.updateDetails(bo));
    }
}
